class Solution:

    def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:
        f = [0] * len(s2)
        for p2 in range(len(s2)):
            j = p2
            for v1 in s1:
                if s2[j] == v1:
                    f[p2] += 1
                    j = (j + 1) % len(s2)
        tot = p2 = 0
        for _ in range(n1):
            add = f[p2]
            tot += add
            p2 = (p2 + add) % len(s2)
        return tot // len(s2) // n2
